package com.rc.saas.tenant.service.acct;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.base.BaseSearch;
import com.rc.saas.tenant.mapper.acct.AcctContractMapper;
import com.rc.saas.tenant.model.acct.AcctContract;
import com.rc.saas.tenant.model.acct.AcctContractExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author frog
 * @date 2021/1/14
 */
@Service
public class AcctContractServiceImpl implements AcctContractService {

    @Autowired
    private AcctContractMapper acctContractMapper;

    @Override
    public AcctContractMapper getMapper() {
        return acctContractMapper;
    }

    @Override
    public PageInfo<AcctContract> listPageAcctContract(BaseSearch baseSearch, Long operatorStationId) {
        PageHelper.startPage(baseSearch.getOffset(), baseSearch.getLimit());
        List<AcctContract> list = listContract(operatorStationId);
        return new PageInfo<AcctContract>(list);
    }

    @Override
    public List<AcctContract> listAcctContract(Long operatorStationId) {
        List<AcctContract> list = listContract(operatorStationId);
        return list;
    }

    private List<AcctContract> listContract(Long operatorStationId) {
        AcctContractExample acctContractExample = new AcctContractExample();
        acctContractExample.setOrderByClause("contract_id DESC");
        acctContractExample.createCriteria().andOperatorStationIdEqualTo(operatorStationId).andIsDeleteEqualTo("0");
        return acctContractMapper.selectByExample(acctContractExample);
    }
}
